<!--
 * @Author: Rachel 943701297@qq.com
 * @Date: 2022-07-17 20:15:56
 * @LastEditors: Rachel 943701297@qq.com
 * @LastEditTime: 2022-07-17 20:50:26
 * @FilePath: \JS\java-script-learning-notes\JSCode\cssCode\localStorage.html
 * @Description: 
 * 
 * Copyright (c) 2022 by Rachel 943701297@qq.com, All Rights Reserved. 
-->
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>本地存储</title>
  </head>
  <body>
    <input type="text" />
    <button class="set">存储数据</button>
    <button class="get">get data</button>
    <button class="remove">remove data</button>
    <button class="del">clear all data</button>
  </body>
  <script>
    let ipt = document.querySelector("input");
    let set = document.querySelector(".set");
    let get = document.querySelector(".get");
    let remove = document.querySelector(".remove");
    let del = document.querySelector(".del");
    set.addEventListener("click", function () {
      let val = ipt.value;
      localStorage.setItem("uname", val);
      localStorage.setItem("psw", val);
    });
    get.addEventListener("click", function () {
      alert(localStorage.getItem("uname"));
    });
    remove.addEventListener("click", function () {
      localStorage.removeItem("uname");
    });
    del.addEventListener("click", function () {
      localStorage.clear();
    });
  </script>
</html>
